package com.yuanqi.dz.dc.service.impl;

import com.powermop.service.remote.IRefundInforMation;
import com.yuanqi.dz.dc.util.DZConfigRead;
import com.yuanqitech.powermop.dz.DZDataInterface;
import com.yuanqitech.powermop.dz.DZInfo;
import com.yuanqitech.powermop.dz.DZInfoArray;
import pnbclient.helper.StringHelper;
import pnbclient.util.HSClient;
import pnbclient.util.PnbLogFactory;
import pnblog.PnbLogging;

public class LzfDZServiceImpl
  implements DZDataInterface
{
  public static final PnbLogging LOG = PnbLogFactory.getLogger("DZ_EXT_LOG");

  public static void main(String[] args) {
    new LzfDZServiceImpl().getDZData("105370260120019", "20170111");
  }

  public DZInfoArray getDZData(String mercharnum, String dzdate) {
    DZInfoArray dzInfoArray = new DZInfoArray();
    String lzf_dz_address = DZConfigRead.getProperties("zftx_dz_address");
    if (StringHelper.isEmpty(lzf_dz_address)) {
      dzInfoArray.setRc("-1");
      dzInfoArray.setErrormsg("获取龙支付对账数据HS地址未配置");
      return dzInfoArray;
    }
    LOG.addDebug("create " + IRefundInforMation.class.getSimpleName() + " from:" + lzf_dz_address);
    try
    {
      LOG.addInfo("调用HS接口入参{mercharnum:" + mercharnum + ",dzdate:" + dzdate + "}");
      IRefundInforMation iRefundInforMation = (IRefundInforMation)HSClient.create(IRefundInforMation.class, lzf_dz_address);
      dzInfoArray = iRefundInforMation.getLongPayDZData(mercharnum, dzdate);
      if (dzInfoArray == null) {
        dzInfoArray = new DZInfoArray();
        dzInfoArray.setRc("-1");
        dzInfoArray.setErrormsg("HS获取龙支付对账数据为null");
        return dzInfoArray;
      }
      String rc = dzInfoArray.getRc();
      if ((rc != null) && ("1".equals(rc))) {
        DZInfo[] list = dzInfoArray.getDzInfo();
        if ((list == null) || (list.length == 0)) {
          dzInfoArray = new DZInfoArray();
          dzInfoArray.setRc("-1");
          dzInfoArray.setErrormsg("HS获取龙支付对账数据为空");
          return dzInfoArray;
        }

        dzInfoArray = new DZInfoArray();
        dzInfoArray.setRc("1");
        dzInfoArray.setErrormsg("获取龙支付对账数据成功!");
        dzInfoArray.setDzInfo(list);
      }
    } catch (Exception e) {
      LOG.addError(e);
      dzInfoArray = new DZInfoArray();
      dzInfoArray.setRc("-1");
      dzInfoArray.setErrormsg("HS获取龙支付对账数据异常!");
      return dzInfoArray;
    }

    return dzInfoArray;
  }
}